<template>
  <div  class="content">
    <div class="head">
      <span>流程定义</span>
    </div>

    <Table :height="autoheight" stripe border :loading="loading" :columns="columns1" :data="dataList"></Table>
    <Page :total="totalSize" :current="page" :page-size="pageSize" @on-change="pageNum" @on-page-size-change="pageSizeChange" show-total></Page>
    <div>
      <Modal v-model="modalDel" title="温馨提示" @on-ok="deleteInfo"  @on-cancel="cancel">
        <p>确认要删除吗？</p>
      </Modal>
    </div>
    <div>
      <Modal v-model="startFlowModal" title="开启流程"  @on-cancel="cancel" cancel-text="取消">
        <p>如果要开启流程，请点确认按钮</p>
        <div slot="footer">
          <Button @click="startFlowSubmit();" type="info">确定</Button>
        </div>
      </Modal>
    </div>

  </div>
</template>
<script>
import { autoheight } from "../../../static/js/tool.js";
export default {
  data() {
    return {
      modalDel : false,
      autoheight:400,
      flowParamsItem: {
        fdKey: "",
        fdId : "",
      },
      totalSize: 0,
      pageSize: 20,
      page: 1,
      id: "",
      deploymentId : '',
      startFlowModal: false,
      loading: true,
      columns1: [
        {
          title: "发布ID",
          key: "deploymentId",
          align: "center",
        },
        {
          title: "流程定义名称",
          key: "fdName",
          align: "center",
        },
        {
          title: "流程定义ID",
          key: "fdId",
          align: "center",
        },
        {
          title: "流程定义KEY",
          key: "fdKey",
          align: "center",
        },
        {
          title: "操作",
          key: "action",
          width: 230,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.startFlow(params.row);
                    }
                  }
                },
                "启动流程"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      this.showDelete(params.row);
                    }
                  }
                },
                "删除"
              )
            ]);
          }
        }
      ],
      dataList: []
    };
  },
  mounted() {
    this.initData();
    autoheight(this,180)
  },
  methods: {
    initData() {
      this.loading = true;
      this.$http.post("/api/flow/actflow/define/getAll",{
         pageNum: this.page,
         pageSize: this.pageSize,
      }).then(res => {
        this.dataList = res.retBody;
        this.totalSize = res.retBody.total;
        this.loading = false;
      });
    },

    /**
     * 启动流程
     */
    startFlow(row) {
      this.flowParamsItem.fdId = row.fdId;
      this.startFlowModal = true;
    },

    /**
     * 提交
     */
    startFlowSubmit() {
      const self = this;
      this.$http.post("/api/flow/actflow/instance/createInstance", this.flowParamsItem).then(res => {
        if (res.retHead.code == "0000000") {
          this.startFlowModal = false;
          this.$Message.success({
            top: 100,
            duration: 1,
            content: res.retHead.message
          });
          this.initData();
        } else {
          this.$Message.warning({
            top: 100,
            duration: 1,
            content: res.retHead.message
          });
        }
      });
    },

     /**
     * 删除
     */
    deleteInfo() {
      this.$http.post("/api/flow/actflow/define/doDelDeploymentId", { deploymentId: this.deploymentId }).then(res => {
        if (res.retHead.code == "0000000") {
          this.$Message.success({
            top: 100,
            duration: 3,
            content: res.retHead.message
          });
        } else {
          this.$Message.warning({
            top: 100,
            duration: 3,
            content: res.retHead.message
          });
        }
        this.initData();
      });
    },

    cancel() {},
    deleteCancel() {},
    /**
     * 改变页码
     */
    pageNum(page) {
      this.loading = true;
      this.page = page;
      this.initData();
    },
    /**
     * 改变每页的条数
     */
    pageSizeChange(pageSize) {
      this.loading = true;
      this.pageSize = pageSize;
      this.initData();
    },
    //删除提示框
    showDelete(row){
      this.modalDel = true;
      this.deploymentId = row.deploymentId;
    },
  }
};
</script>

